//
//  HWManagementTableViewCell.m
//  HWPromoteProjectAPP
//
//  Created by 陈道斌 on 2020/2/24.
//  Copyright © 2020 陈道斌. All rights reserved.
//

#import "HWManagementTableViewCell.h"


@interface HWManagementTableViewCell()
@property(strong,nonatomic) UILabel *miaoshuLabel;
@property(strong,nonatomic) UIView *fengexianView;


@end





@implementation HWManagementTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
        
        
    }
    
    
    
    return  self;
    
    
    
    
    
}


//设置UI

- (void)setupUI {

     self.miaoshuLabel  = [[UILabel alloc]initWithFrame:CGRectMake(20, 20, 300, 25)];
     self.miaoshuLabel.text = @"游戏管理";
     self.miaoshuLabel.textAlignment =  NSTextAlignmentLeft;
     self.miaoshuLabel.textColor = RGB(68, 68, 68);
     self.miaoshuLabel.font = [UIFont systemFontOfSize:18];
     [self.contentView  addSubview:self.miaoshuLabel];
    
    
    
    self.fengexianView = [[UIView alloc]initWithFrame:CGRectMake(0, 65+47+19, kScreenW, 1)];
    

    self.fengexianView.backgroundColor = [UIColor redColor];
    
    self.fengexianView.backgroundColor = RGB(245, 245, 245);
    
    [self.contentView addSubview: self.fengexianView];
    
    
    
}


//设置NSDiac
- (void)setDataDic:(NSDictionary *)dataDic {
    
    
    
  
      _dataDic = dataDic;
    

      for(UIView *tmpView in [self.contentView subviews]) {
        
        if (tmpView.tag > 99) {
            [tmpView removeFromSuperview];
            
         }
        
        
      }
    
      self.miaoshuLabel.text = [NSString stringWithFormat:@"%@",dataDic[@"title"]];
    
    
 
      NSMutableArray  *dataArr = [dataDic[@"list"] mutableCopy];
    
    
       if (dataArr.count > 3 ) {
           
             CGFloat hengjianjuLiin = (kScreenW -  55*4)/5;
                     

                 for (int i = 0 ; i < dataArr.count; i++) {
                         
                             int row = i/4;
                             int line = i%4;
//                             int shulian = (line*2+2) -1;

                             UIView *redview = [[UIView alloc]initWithFrame:CGRectMake(hengjianjuLiin+hengjianjuLiin*line+line*55, row*20+row*47+65, 55,47 )];
                           
                           
                             redview.tag = i+100;
                            redview.backgroundColor = [UIColor whiteColor];
                             //  redview.backgroundColor = [UIColor redColor];
                             [ self.contentView  addSubview:redview];
                             
                             
                             
                             NSDictionary *dic = dataArr[i];
                             

                             
                             UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(imviewTaKaifu:)];
                             [redview addGestureRecognizer:tap1];
                             
                             
                             UIImageView *imview = [[UIImageView alloc]initWithFrame:CGRectMake(15, 0,  24, 24)];
                           //  imview.image = [UIImage imageNamed:paihangbangcoArr[i]];
                             imview.userInteractionEnabled = YES;
                             imview.tag = i;
                             [redview addSubview:imview];
                         
                             NSString *imageStr = dic[@"image"];
                           
                             [imview sd_setImageWithURL:[NSURL URLWithString:imageStr]  placeholderImage:nil];
                           
                           
                             
                             
                         
                             
                            // UILabel
                             UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 30, 55, 17)];
                           
                             nameLabel.textAlignment = NSTextAlignmentCenter;
                             nameLabel.font = [UIFont systemFontOfSize:12];
                             nameLabel.textColor = RGB(68, 68, 68);
                             [redview addSubview:nameLabel];
                             
                             nameLabel.text =  [NSString stringWithFormat:@"%@",dic[@"title"]];
                          //   [self.labelMuArr addObject:nameLabel];
                             
                         
                         }
                  
           
           
   
       } else {
           
           CGFloat hengjianjuLiin = (kScreenW -  55*3)/4;
              

          for (int i = 0 ; i < dataArr.count; i++) {
                  
                      int row = i/3;
                      int line = i%3;
//                      int shulian = (line*2+2) -1;

                      UIView *redview = [[UIView alloc]initWithFrame:CGRectMake(hengjianjuLiin+hengjianjuLiin*line+line*55, row*20+row*47+65, 55,47 )];
                    
                    
                      redview.tag = i+100;
                     redview.backgroundColor = [UIColor whiteColor];
                     //   redview.backgroundColor = [UIColor redColor];
                      [ self.contentView  addSubview:redview];
                      
                      
                      
                      NSDictionary *dic = dataArr[i];
                      

                      
                      UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(imviewTaKaifu:)];
                      [redview addGestureRecognizer:tap1];
                      
                      
                      UIImageView *imview = [[UIImageView alloc]initWithFrame:CGRectMake(15, 0,  24, 24)];
                    //  imview.image = [UIImage imageNamed:paihangbangcoArr[i]];
                      imview.userInteractionEnabled = YES;
                      imview.tag = i;
                      [redview addSubview:imview];
                  
                      NSString *imageStr = dic[@"image"];
                    
                      [imview sd_setImageWithURL:[NSURL URLWithString:imageStr]  placeholderImage:nil];
                    
                    
                      
                      
                  
                      
                     // UILabel
                      UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 30, 55, 17)];
                    
                      nameLabel.textAlignment = NSTextAlignmentCenter;
                      nameLabel.font = [UIFont systemFontOfSize:12];
                      nameLabel.textColor = RGB(68, 68, 68);
                      [redview addSubview:nameLabel];
                      
                      nameLabel.text =  [NSString stringWithFormat:@"%@",dic[@"title"]];
                   //   [self.labelMuArr addObject:nameLabel];
                      
                  
                  }
           
           
           
       }
    
    
    
    
     
    
    
    
     
    
    
    
    
    
    
}



- (void)imviewTaKaifu:(UITapGestureRecognizer *)sender {
    
    UIView *view = sender.view;
    NSInteger tag = view.tag - 100;
    
     //  NSMutableArray  *dataArr = seldataDic[@"list"] 
    
    NSMutableArray  *dataArr = self.dataDic[@"list"];
    
    NSLog(@"%@",dataArr[tag]);

    [self.delegate HWManagementTableViewCellshuju:dataArr[tag]];
    
    
    
    
    
    
}




@end
